package com.dzm.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dzm.entity.LoginUser;
import com.dzm.entity.User;
import com.dzm.service.UserService;
import com.dzm.mapper.UserMapper;
import com.dzm.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author Dzm
* @description 针对表【sys_user】的数据库操作Service实现
* @createDate 2024-08-24 09:33:35
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public LoginUser getUserByVo(LoginVo loginVo) {
        String username = loginVo.getUsername();
        String password = SecureUtil.md5(loginVo.getPassword());

        User user = userMapper.selectOne(new LambdaQueryWrapper<User>()
                .eq(User::getUsername, username)
                .eq(User::getPassword, password));

        if(user != null) {
            LoginUser loginUser = new LoginUser();
            loginUser.setUser(user);
            return loginUser;
        }

        return null;
    }
}




